@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <link href="/lib/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.min.js"></script>
    <script type="text/javascript" src="/lib/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script src="/js/upload.js" type="text/javascript"></script>
    <script src="/js/mobileBUGFix.mini.js" type="text/javascript"></script>
    <div class="content">
        <!-- <div class="header">
            <ul class="breadcrumb">
                <li><a href="">更新设置</a> </li>
            </ul>
        </div> -->
        <div class="main-content header">
            <div class="btn-group btn-group-lg" role="group" aria-label="...">
              
                <a class="btn btn-default   @if($info=='index') active @endif" href="/establish/update?info=index" >首页</a>
                <a class="btn btn-default @if($info=='article') active @endif" href="/establish/update?info=article">发现页</a>
                <a class="btn btn-default @if($info=='course') active @endif" href="/establish/update?info=course">课程页</a>
               
            </div>
        </div>
        
        <div class="panel panel-default">
            <div class="panel-heading no-collapse">分类列表</div>
            <table class="table table-hover">
                  <thead>
                    <tr>
                      <th>序号</th>
                      <th>栏目名称</th>
                      <th>状态</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                <tbody>
                @if($info=='index')
                    <div class="panel-group">
                        <tr>
                            <td>1</td>
                            <td>首页</td>
                            <td>
                                <a href="javascript:;" class="btn btn-success">显示</a> 
                            </td>
                            <td>
                                <a href="javascript:;" class="btn btn-info" data-id="index" onclick="updateCache(this)">更新</a>
                            </td>
                        </tr>
                    </div>


                @else    
                    <div class="panel-group">
                    @if($info == 'article')
                        <tr>
                            <td>0</td>
                            <td>精选</td>
                            <td>
                                <a href="javascript:;" class="btn btn-success">显示</a> 
                            </td>
                            <td>
                                <a href="javascript:;" class="btn btn-info" data-id="0" onclick="updateCache(this)">更新</a>
                            </td>
                        </tr>
                    @endif
                    @if(count($data))
                        @foreach($data as $k)
                            <tr>
                                <td>{{$k->id}}</td>
                                <td>{{$k->title}}</td>
                                <td>
                                    @if($k->state == 1) 
                                      <a href="@if($info == 'course') javascript:; @else /type/state?id={{$k->id}}&state=0 @endif" class="btn btn-success">显示</a> 
                                    @else 
                                      <a href="@if($info == 'course') javascript:; @else   /type/state?id={{$k->id}}&state=1 @endif" type="button" class="btn btn-danger">禁用</a>
                                    @endif
                                </td>
                                <td>
                                    <a href="javascript:;" class="btn btn-info" data-id="{{$k->id}}" onclick="updateCache(this)">更新</a>
                                </td>
                            </tr>
                            @if($info == "course")
                                @foreach($k->two as $a)
                                <tr>
                                    <td>{{$a->id}}</td>
                                    <td>├├├{{$a->title}}</td>
                                    <td>
                                        @if($a->state == 1) 
                                          <a href="javascript:;" class="btn btn-success">显示</a> 
                                        @else 
                                          <a href="javascript:;" type="button" class="btn btn-danger">禁用</a>
                                        @endif
                                    </td>
                                    <td>
                                        <a href="javascript:;" class="btn btn-info" data-id="{{$a->id}}" onclick="updateCache(this)">更新</a>
                                    </td>
                                </tr>
                                @endforeach
                            @endif
                        @endforeach
                    @endif
                    </div>
                @endif
                </tbody>
            </table>
        </div>
    </div>
    <script src="/lib/jquery.validate.js" type="text/javascript"></script>
    <script>
        function updateCache(e){
            var info = e.getAttribute("data-id");
            var list = '{{$info}}';
            console.log(list);
            var token     = '{{csrf_token()}}';
            $.ajax({
                type:"POST",
                url:"/establish/updateCache",
                data:{info:info,list:list,_token:token},
                dataType:"json",
                success:function(result){
                    if(result.code==1){
                        alert('操作成功');
                    }else{
                        alert('失败');
                    }
                }
            });
        }
    </script>
    
@endsection